textview: Add draw_layer vfunc
authorAlexander Larsson <alexl@redhat.com>
Mon, 28 Jul 2014 13:20:52 +0000 (15:20 +0200)
committerAlexander Larsson <alexl@redhat.com>
Mon, 28 Jul 2014 14:23:33 +0000 (16:23 +0200)
This allows subclasses to render things below and above the text
in the text view. This allows e.g. GtkSourceView to highlight the
cursor row and to render overlays for colum 80. This used to be done
by rendering before/after chaining up to the parent, but that doesn't
work anymore since the view now renders a background, and due to the
use of the pixel cache.

gtk/gtktextview.c
gtk/gtktextview.h

index 40b25960a930a90d07728e0511123a6ec4420374..1a01582a718c7e1b7800d46f1c4277ba5c471052 100644 (file)
@@ -5311,6 +5311,7 @@ draw_text (cairo_t  *cr,
            gpointer  user_data)
 {
   GtkWidget *widget = user_data;
+  GtkTextView *text_view = GTK_TEXT_VIEW (widget);
   GtkStyleContext *context;
   GdkRectangle bg_rect;
 
@@ -5324,7 +5325,13 @@ draw_text (cairo_t  *cr,
                          bg_rect.width, bg_rect.height);
   gtk_style_context_restore (context);
 
+  if (GTK_TEXT_VIEW_GET_CLASS (text_view)->draw_layer != NULL)
+    GTK_TEXT_VIEW_GET_CLASS (text_view)->draw_layer (widget, GTK_TEXT_VIEW_LAYER_BELOW, cr);
+
   gtk_text_view_paint (widget, cr);
+
+  if (GTK_TEXT_VIEW_GET_CLASS (text_view)->draw_layer != NULL)
+    GTK_TEXT_VIEW_GET_CLASS (text_view)->draw_layer (widget, GTK_TEXT_VIEW_LAYER_ABOVE, cr);
 }
 
 static void
index 46f57fd37ebc96056930939e7638b98df0ec0557..aaa03562f8be0b559602f394c5ae12f319a04d9a 100644 (file)
@@ -67,6 +67,19 @@ typedef enum
   GTK_TEXT_WINDOW_BOTTOM
 } GtkTextWindowType;
 
+/**
+ * GtkTextViewLayer:
+ * @GTK_TEXT_VIEW_LAYER_BELOW: The layer rendered below the text (but above the background).
+ * @GTK_TEXT_VIEW_LAYER_ABOVE: The layer rendered above the text.
+ *
+ * Used to reference the parts of #GtkTextView.
+ */
+typedef enum
+{
+  GTK_TEXT_VIEW_LAYER_BELOW,
+  GTK_TEXT_VIEW_LAYER_ABOVE
+} GtkTextViewLayer;
+
 /**
  * GTK_TEXT_VIEW_PRIORITY_VALIDATE:
  *
@@ -86,6 +99,11 @@ struct _GtkTextView
   GtkTextViewPrivate *priv;
 };
 
+/**
+ * GtkTextViewClass:
+ * @parent_class: The object class structure needs to be the first
+ * @draw_layer: Draw layers below and above the text in the text window.
+ */
 struct _GtkTextViewClass
 {
   GtkContainerClass parent_class;
@@ -121,6 +139,10 @@ struct _GtkTextViewClass
 
   GtkTextBuffer * (* create_buffer) (GtkTextView *text_view);
 
+  void (* draw_layer)       (GtkWidget        *widget,
+                            GtkTextViewLayer layer,
+                            cairo_t          *cr);
+
   /* Padding for future expansion */
   void (*_gtk_reserved1) (void);
   void (*_gtk_reserved2) (void);
@@ -128,7 +150,6 @@ struct _GtkTextViewClass
   void (*_gtk_reserved4) (void);
   void (*_gtk_reserved5) (void);
   void (*_gtk_reserved6) (void);
-  void (*_gtk_reserved7) (void);
 };
 
 GDK_AVAILABLE_IN_ALL